<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="shortcut icon" href="../../favicon.ico" type="image/x-icon">
	<title>react_state</title>
</head>
<body>
  <div id="test"></div>

  <script type="text/javascript" src="../../js/react.development.js" ></script>
  <script type="text/javascript" src="../../js/react-dom.development.js"></script>
  <script type="text/javascript" src="../../js/babel.min.js"></script>

  <script type="text/babel">
    class Weather extends React.Component {
      state = {isCool: true, wind: '微风'}

      changeWeather = ()=>{
        this.setState(state=>({
          isCool: !state.isCool
        }))
      }

      render(){
        const {isCool, wind} = this.state;
        const weather = isCool?'凉爽':'炎热';

        return <h1 onClick={this.changeWeather}>今天天气很{weather}, {wind}</h1>
      }
    }

    ReactDOM.render(<Weather />, document.getElementById('test'));
  </script>
</body>